package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static org.social.db.StaticResource.PlayerMapResource.*;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import org.social.db.cache.PlayerMapCache;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.PlayerMapResource.*;
/**
 * 玩家映射表
 */
public class PlayerMap extends BasePojo<PlayerMap> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 账号库ID
	*/
	private String uid;
	
	/**
	* 玩家ID
	*/
	private int pid;
	
	/**
	* 服务器ID
	*/
	private String serverId;
	
	/**
	* 玩家信息
	*/
	private Map info;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static PlayerMap builder() {
		PlayerMap playerMap = new PlayerMap();
		return playerMap;
	}
	
	@Deprecated
	public PlayerMap() {
		super();
	}
	
	public PlayerMap(int id, String uid, int pid, String serverId, Map info) {
		super();
		this.id = id;
		this.uid = uid;
		this.pid = pid;
		this.serverId = serverId;
		this.info = info;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public PlayerMap setId(int id) {this.id = id;return this;}
	
	/**
	 * 账号库ID
	 */
	public String getUid() {return uid;}
	
	/**
	 * 账号库ID
	 */
	public PlayerMap setUid(String uid) {this.uid = uid;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPid() {return pid;}
	
	/**
	 * 玩家ID
	 */
	public PlayerMap setPid(int pid) {this.pid = pid;return this;}
	
	/**
	 * 服务器ID
	 */
	public String getServerId() {return serverId;}
	
	/**
	 * 服务器ID
	 */
	public PlayerMap setServerId(String serverId) {this.serverId = serverId;return this;}
	
	/**
	 * 玩家信息
	 */
	public Map getInfo() {return info;}
	
	/**
	 * 玩家信息
	 */
	public PlayerMap setInfo(Map info) {this.info = info;return this;}
	
	/**
	 * 玩家信息
	 */
	public byte[] getInfoByte() {
		return toBytes(info);
	}
	
	/**
	 * 玩家信息
	 */
	public Map initInfoByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected PlayerMap setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected PlayerMap setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	private org.social.db.proxy.bean.PlayerMapProxy playerMapProxy = new org.social.db.proxy.bean.PlayerMapProxy().build(this);
	
	public org.social.db.proxy.bean.PlayerMapProxy getPlayerMapProxy(){return playerMapProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.uid;
        values[2] = this.pid;
        values[3] = this.serverId;
        values[4] = this.info;
        values[5] = this.createDate;
        values[6] = this.modifiedDate;
        return values;
	}
	
	public PlayerMap deepCopy(){
		PlayerMap playerMap = null;
		try {
			playerMap = (PlayerMap) super.clone();
		    playerMap.setInfo(ToolCopy.copyObject(this.info));
		    playerMap.setCreateDate(ToolCopy.copyObject(this.createDate));
		    playerMap.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    playerMap.indexValues = ArrayUtils.clone(indexValues);
			return playerMap;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return playerMap;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.uid);
        map.put(keys[2], this.pid);
        map.put(keys[3], this.serverId);
        map.put(keys[4], this.info);
        map.put(keys[5], this.createDate);
        map.put(keys[6], this.modifiedDate);
        return map;
    }
    
    protected PlayerMap createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.uid = (String)map.get(keys[1]);
   		this.pid = (int)map.get(keys[2]);
   		this.serverId = (String)map.get(keys[3]);
   		this.info = (Map)map.get(keys[4]);
   		this.createDate = (java.util.Date)map.get(keys[5]);
   		this.modifiedDate = (java.util.Date)map.get(keys[6]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.uid);
        obj.put(keys[2], this.pid);
        obj.put(keys[3], this.serverId);
        obj.put(keys[4], toBytes(info));
        obj.put(keys[5], this.createDate);
        obj.put(keys[6], this.modifiedDate);
        return obj;
    }
    
    protected PlayerMap createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.uid = obj.getString(keys[1]);
	    this.pid = obj.getIntValue(keys[2]);
	    this.serverId = obj.getString(keys[3]);
		this.info = (Map)forBytesObject(obj.getBytes(keys[4]));
	    this.createDate = obj.getDate(keys[5]);
	    this.modifiedDate = obj.getDate(keys[6]);
        return this;
    }
    
    
    public PlayerMap createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.uid = rs.getString(SOURCE_COLUMN_NAMES[1]);
	    this.pid = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.serverId = rs.getString(SOURCE_COLUMN_NAMES[3]);
		this.info = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[4]));
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.uid);
	    byteBuf.writeInt(this.pid);
	    byteBuf.writeString(this.serverId);
	    byteBuf.writeObject(this.info);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected PlayerMap readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.uid = byteBuf.readString(null);
	    this.pid = byteBuf.readInt(null);
	    this.serverId = byteBuf.readString(null);
	    this.info = (Map)byteBuf.readObject();
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public PlayerMap insert(){
    	return PlayerMapCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public PlayerMap update(){
    	return PlayerMapCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return PlayerMapCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public PlayerMap insertAndFlush(){
    	return PlayerMapCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public PlayerMap updateAndFlush(){
    	return PlayerMapCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return PlayerMapCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public PlayerMap syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPid()).e();
		indexValues[2] = SK_Plus.b(getUid()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}